<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="订单号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="子订单号" prop="secondOrderNumber">
        <el-input
          v-model="queryParams.secondOrderNumber"
          placeholder="子订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单日期" prop="orderNumber">
        <el-date-picker
          v-model="value2"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          @change="changeTime"
          size="mini"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>

      <div v-if="isOpen">
        <el-form-item label="品牌" prop="brand">
          <el-input
            v-model="queryParams.brand"
            placeholder="请输入品牌"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="渠道" prop="channel">
          <el-input
            v-model="queryParams.channel"
            placeholder="请输入渠道"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="店铺" prop="shopName">
          <el-input
            v-model="queryParams.shopName"
            placeholder="请输入店铺"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品编码" prop="productCode">
          <el-input
            v-model="queryParams.productCode"
            placeholder="请输入商品编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品件数" prop="productQuantity">
          <el-input
            v-model="queryParams.productQuantity"
            placeholder="请输入商品件数"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="商品平均单价" prop="avgProPrice">
          <el-input
            v-model="queryParams.avgProPrice"
            placeholder="请输入商品平均单价"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="支付时间" prop="dataDate">
          <el-date-picker
            clearable
            v-model="queryParams.dataDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付金额" prop="payAmount">
          <el-input
            v-model="queryParams.payAmount"
            placeholder="请输入支付金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="退款金额" prop="returnAmount">
          <el-input
            v-model="queryParams.returnAmount"
            placeholder="请输入退款金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="折扣率" prop="discountRate">
          <el-input
            v-model="queryParams.discountRate"
            placeholder="请输入折扣率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="达人id" prop="talentId">
          <el-input
            v-model="queryParams.talentId"
            placeholder="请输入达人id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="达人名称" prop="talentName">
          <el-input
            v-model="queryParams.talentName"
            placeholder="请输入达人名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="预估佣金" prop="estimateCommission">
          <el-input
            v-model="queryParams.estimateCommission"
            placeholder="请输入预估佣金"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="佣金率" prop="commissionRate">
          <el-input
            v-model="queryParams.commissionRate"
            placeholder="请输入佣金率"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="年" prop="dataYear">
          <el-input
            v-model="queryParams.dataYear"
            placeholder="请输入年"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="月" prop="dataMonth">
          <el-input
            v-model="queryParams.dataMonth"
            placeholder="请输入月"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="周" prop="dataWeek">
          <el-input
            v-model="queryParams.dataWeek"
            placeholder="请输入周"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> -->
    </el-form>

    <el-dialog
      :visible.sync="openInfo"
      width="700px"
      append-to-body
      title="选择时间"
    >
      <timeSearch
        @getDateArr="getDateArr"
        @changDay="changDay"
        :timeArr="timeArr"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleRefreshsyncData"
          >同步基础数据</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="opensyncInfo"
      width="700px"
      append-to-body
      title="选择时间"
    >
      <timeSearch
        @getDateArr="getDateArr"
        @changDay="changDay"
        :timeArr="timeArr"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handlesyncProductType"
          >同步品类数据</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="opensyncDataCheck"
      width="700px"
      append-to-body
      title="选择时间"
    >
      <timeSearch
        @getDateArr="getDateArr"
        @changDay="changDay"
        :timeArr="timeArr"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <!-- <el-form :inline="true">
        <el-form-item label="延时秒数" prop="second">
          <el-input v-model="second" placeholder="延时秒数" />
        </el-form-item>
      </el-form> -->
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handlesyncDataCheck"
          >异常检测</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="opengift"
      width="700px"
      append-to-body
      title="选择时间"
    >
      <timeSearch
        @getDateArr="getDateArr"
        @changDay="changDay"
        :timeArr="timeArr"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleupdateGiftLiveType"
          >修改赠品直播类型归属</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['live:BiLiveOrder:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['live:BiLiveOrder:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['live:BiLiveOrder:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['live:BiLiveOrder:export']"
          >导出</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button size="mini" plain icon="el-icon-upload" @click="daoru"
          >导入</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefresh"
          >同步达播数据</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshsynOrderStatusData"
          >同步订单状态</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshsynProTypeData"
          >同步品类信息</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="openInfo = true"
          >同步基础数据</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" @click="opensyncInfo = true"
          >同步品类数据</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" @click="opensyncDataCheck = true"
          >异常检测</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" @click="handlesetLiveTypeAffiliation"
          >同步直播类型归属</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" @click="opengift = true"
          >修改赠品直播类型归属</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" @click="openone = true">一键同步</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" @click="handlesetReturnAmountById"
          >计算退款金额</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-dialog
      :visible.sync="opensetLiveTypeAffiliation"
      width="700px"
      append-to-body
      title="选择时间"
    >
      <timeSearch
        @getDateArr="getDateArr"
        @changDay="changDay"
        :timeArr="timeArr"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitsetLiveTypeAffiliation"
          >同步直播类型归属</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="openone"
      width="700px"
      append-to-body
      title="选择时间"
    >
      <timeSearch
        @getDateArr="getDateArr"
        @changDay="changDay"
        :timeArr="timeArr"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitoneClickSync"
          >一键同步</el-button
        >
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>

    <el-table
      v-loading="loading"
      :data="BiLiveOrderList"
      @selection-change="handleSelectionChange"
      :height="650"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column width="120" label="品牌" align="center" prop="brand" />
      <el-table-column width="120" label="渠道" align="center" prop="channel" />
      <el-table-column
        width="120"
        label="店铺"
        align="center"
        prop="shopName"
      />
      <el-table-column
        width="120"
        label="订单号"
        align="center"
        prop="orderNumber"
      />
      <el-table-column
        width="120"
        label="子订单号"
        align="center"
        prop="secondOrderNumber"
      />
      <el-table-column
        width="120"
        label="订单状态"
        align="center"
        prop="orderStatus"
      />
      <el-table-column
        width="120"
        label="结算状态"
        align="center"
        prop="countStatus"
      />
      <el-table-column
        width="120"
        label="售后状态"
        align="center"
        prop="afterSaleStatus"
      />
      <el-table-column
        width="120"
        label="商品编码"
        align="center"
        prop="productCode"
      />
      <el-table-column width="120" label="款式编码" align="center" prop="spu" />
      <el-table-column width="120" label="item" align="center" prop="item" />
      <el-table-column
        width="120"
        label="商品件数"
        align="center"
        prop="productQuantity"
      />
      <el-table-column
        width="120"
        label="商品平均单价"
        align="center"
        prop="avgProPrice"
      />
      <el-table-column
        width="120"
        label="品类"
        align="center"
        prop="productType"
      />
      <el-table-column
        width="120"
        label="直播类型"
        align="center"
        prop="liveType"
      />
      <el-table-column
        width="120"
        label="直播类型归属"
        align="center"
        prop="liveTypeAffiliation"
      />
      <el-table-column
        width="120"
        label="广告渠道"
        align="center"
        prop="advertisingChannel"
      />
      <el-table-column
        width="120"
        label="流量类型"
        align="center"
        prop="flowCarrierType"
      />
      <el-table-column
        width="120"
        label="流量体裁"
        align="center"
        prop="flowType"
      />
      <el-table-column
        width="120"
        label="流量渠道"
        align="center"
        prop="flowChannel"
      />
      <el-table-column
        width="120"
        label="支付时间"
        align="center"
        prop="dataDate"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dataDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        width="120"
        label="支付金额"
        align="center"
        prop="payAmount"
      />
      <el-table-column
        width="120"
        label="退货数量"
        align="center"
        prop="returnQuantity"
      />
      <el-table-column
        width="120"
        label="退款金额"
        align="center"
        prop="returnAmount"
      />
      <el-table-column
        width="120"
        label="折扣率"
        align="center"
        prop="discountRate"
      />
      <el-table-column
        width="120"
        label="达人id"
        align="center"
        prop="talentId"
      />
      <el-table-column
        width="120"
        label="达人名称"
        align="center"
        prop="talentName"
      />
      <el-table-column
        width="120"
        label="预估佣金"
        align="center"
        prop="estimateCommission"
      />
      <el-table-column
        width="120"
        label="佣金率"
        align="center"
        prop="commissionRate"
      />
      <el-table-column width="120" label="年" align="center" prop="dataYear" />
      <el-table-column width="120" label="月" align="center" prop="dataMonth" />
      <el-table-column width="120" label="周" align="center" prop="dataWeek" />
      <el-table-column
        width="120"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['live:BiLiveOrder:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['live:BiLiveOrder:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改直播订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="渠道" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入渠道" />
        </el-form-item>
        <el-form-item label="店铺" prop="shopName">
          <el-input v-model="form.shopName" placeholder="请输入店铺" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="商品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入商品编码" />
        </el-form-item>
        <el-form-item label="商品件数" prop="productQuantity">
          <el-input
            v-model="form.productQuantity"
            placeholder="请输入商品件数"
          />
        </el-form-item>
        <el-form-item label="商品平均单价" prop="avgProPrice">
          <el-input
            v-model="form.avgProPrice"
            placeholder="请输入商品平均单价"
          />
        </el-form-item>
        <el-form-item label="支付时间" prop="dataDate">
          <el-date-picker
            clearable
            v-model="form.dataDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付金额" prop="payAmount">
          <el-input v-model="form.payAmount" placeholder="请输入支付金额" />
        </el-form-item>
        <el-form-item label="退款金额" prop="returnAmount">
          <el-input v-model="form.returnAmount" placeholder="请输入退款金额" />
        </el-form-item>
        <el-form-item label="折扣率" prop="discountRate">
          <el-input v-model="form.discountRate" placeholder="请输入折扣率" />
        </el-form-item>
        <el-form-item label="达人id" prop="talentId">
          <el-input v-model="form.talentId" placeholder="请输入达人id" />
        </el-form-item>
        <el-form-item label="达人名称" prop="talentName">
          <el-input v-model="form.talentName" placeholder="请输入达人名称" />
        </el-form-item>
        <el-form-item label="预估佣金" prop="estimateCommission">
          <el-input
            v-model="form.estimateCommission"
            placeholder="请输入预估佣金"
          />
        </el-form-item>
        <el-form-item label="佣金率" prop="commissionRate">
          <el-input v-model="form.commissionRate" placeholder="请输入佣金率" />
        </el-form-item>
        <el-form-item label="年" prop="dataYear">
          <el-input v-model="form.dataYear" placeholder="请输入年" />
        </el-form-item>
        <el-form-item label="月" prop="dataMonth">
          <el-input v-model="form.dataMonth" placeholder="请输入月" />
        </el-form-item>
        <el-form-item label="周" prop="dataWeek">
          <el-input v-model="form.dataWeek" placeholder="请输入周" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      title="导入"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
      v-if="dialogVisible"
    >
      <!-- 文件上传-->
      <el-form
        :rules="rules"
        :model="dataForm"
        ref="dataForm"
        label-width="150px"
        @submit.native.prevent
      >
        <el-form-item label="文件：" prop="file">
          <el-upload
            class="upload-import"
            ref="uploadImport"
            :http-request="httpRequest"
            action=""
            :on-remove="handleRemove"
            :file-list="fileList"
            :limit="1"
            :on-change="handleChange"
            :auto-upload="false"
            :before-upload="beforeAvatarUpload"
          >
            <!--
            accept="application/zip,.zip" 设置接收的文件类型-->
            <el-button
              v-show="!hasFile"
              slot="trigger"
              size="small"
              type="primary"
              >选取文件</el-button
            >
            <!-- <div slot="tip" class="el-upload__tip">
          只能上传zip文件，且不超过10M
        </div> -->
          </el-upload>
          <!-- 关闭自动上传-->
        </el-form-item>
        <el-form-item label="店铺：" prop="name">
          <!-- <el-input
            type="text"
            v-model.trim="dataForm.name"
            clearable
          ></el-input> -->
          <el-cascader
            class="cascader-limited-scroll"
            v-model="dataForm.name"
            placeholder="选择店铺分组"
            :options="cascadeList"
            :props="{ checkStrictly: true }"
            style="width: 300px; height: 30px"
            @change="changecascadeList"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitUpload">提交</el-button>
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
          <el-button @click="dialogVisible = false">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import timeSearch from "@/common/day";
import {
  listBiLiveTalent,
  getBiLiveTalent,
  delBiLiveTalent,
  addBiLiveTalent,
  updateBiLiveTalent,
  synTalentData,
} from "@/api/live/BiLiveTalent";
import { listAll, importBiKeyword } from "@/api/chart/brandChannelShop";
import {
  listBiLiveOrder,
  getBiLiveOrder,
  delBiLiveOrder,
  addBiLiveOrder,
  updateBiLiveOrder,
  synProTypeData,
  synOrderStatusData,
  syncData,
  syncProductType,
  syncDataCheck,
  setLiveTypeAffiliation,
  updateGiftLiveType,
  oneClickSync,
  setReturnAmountById,
} from "@/api/live/BiLiveOrder";
import axios from "axios";
//--------导入token
import { getToken } from "@/utils/auth";
import moment from "moment";
export default {
  name: "BiLiveOrder",
  components: { timeSearch },
  data() {
    return {
      openone: false,
      opengift: false,
      second: "0",
      opensetLiveTypeAffiliation: false,
      list: [],
      opensyncDataCheck: false,
      openitem: false,
      opensyncInfo: false,
      openInfo: false,
      dayActive: 2,
      timeArr: [
        { value: "2", label: "昨天" },
        { value: "7", label: "最近7天" },
        { value: "30", label: "最近30天" },
        { value: "365", label: "最近一年" },
        { value: "1", label: "日" },
      ],
      timeGap: { startTime: "", endTime: "" },

      cascadeList: [],
      dataForm: {
        name: [],
        file: null,
      },
      rules: {
        name: [
          { required: true, message: "请输入名称", trigger: "blur" },
          { max: 50, message: "最长可输入50个字符", trigger: "blur" },
          // { validator: isvalidatName, trigger: "blur" },
        ],
        file: [{ required: true, message: "请选择上传文件", trigger: "blur" }],
      },
      hasFile: false,
      fileList: [],
      dialogVisible: false,
      pjtUrl: process.env.VUE_APP_BASE_API,

      isOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 直播订单表格数据
      BiLiveOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brand: null,
        channel: null,
        shopName: null,
        orderNumber: null,
        orderStatus: null,
        productCode: null,
        productQuantity: null,
        avgProPrice: null,
        productType: null,
        liveType: null,
        dataDate: null,
        payAmount: null,
        returnAmount: null,
        discountRate: null,
        talentId: null,
        talentName: null,
        estimateCommission: null,
        commissionRate: null,
        dataYear: null,
        dataMonth: null,
        dataWeek: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: "",
      value2: "",
    };
  },
  created() {
    this.getList();
    this.getdataSourceList();
  },
  methods: {
    handlesetReturnAmountById() {
      if (this.ids.length < 1) {
        this.$modal.msgError("请至少选择一条数据");
        return;
      }
      setReturnAmountById(this.ids).then(() => {
        this.$modal.msgSuccess("计算数据成功");
        // this.$modal.closeLoading();
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    changeTime() {
      // console.log(JSON.stringify(this.value2));
      let m1 = moment(this.value2[0]).format("YYYY-MM-DD");
      let m2 = moment(this.value2[1]).format("YYYY-MM-DD");
      // console.log(JSON.stringify(m1));
      // console.log(JSON.stringify(m2));
      this.queryParams.startDate = m1;
      this.queryParams.endDate = m2;
    },
    //时间控件
    changDay(val) {
      this.dayActive = val;
      this.timeGap.startTime = val[0];
      this.timeGap.endTime = val[1];
    },
    getDateArr(value) {
      this.timeGap.startTime = value[0];
      this.timeGap.endTime = value[1];
      console.log(JSON.stringify(this.timeGap));
      this.dayActive = 1;
    },
    // 打开加载层
    openLoading1() {
      this.$modal.loading("正在加载数据，请稍候！");
    },
    /** 刷新缓存按钮操作 Warning*/
    handleRefresh() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      // const obj = {
      //   startTime: this.timeGap.startTime,
      //   endTime: this.timeGap.endTime,
      // };
      this.openLoading1();
      synTalentData(this.timeGap).then(() => {
        // this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    handleupdateGiftLiveType() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading1();
      updateGiftLiveType(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.opengift = false;
        this.getList();

        // this.$store.dispatch('dict/cleanDict');
      });
    },
    /** 同步品类信息 Warning*/
    handleRefreshsyncData() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading1();
      syncData(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.openInfo = false;
        this.getList();

        // this.$store.dispatch('dict/cleanDict');
      });
    },
    /** 同步品类信息 Warning*/
    handleRefreshsyncData() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading1();
      syncData(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.openInfo = false;
        this.getList();

        // this.$store.dispatch('dict/cleanDict');
      });
    } /** 同步品类信息 Warning*/,
    handlesyncProductType() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading1();
      syncProductType(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.opensyncInfo = false;
        this.getList();

        // this.$store.dispatch('dict/cleanDict');
      });
    },
    handlesetLiveTypeAffiliation() {
      if (this.list.length > 1) {
        this.$modal.msgError("请只选择一条数据");
        return;
      } else {
        this.opensetLiveTypeAffiliation = true;
      }
    },
    submitsetLiveTypeAffiliation() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
        orderNumber: this.list.length > 0 ? this.list[0].orderNumber : null,
      };
      this.openLoading1();
      setLiveTypeAffiliation(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.opensetLiveTypeAffiliation = false;
        this.getList();

        // this.$store.dispatch('dict/cleanDict');
      });
    },
    handlesyncDataCheck() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
        // second: this.second,
      };
      this.openLoading1();
      syncDataCheck(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.opensyncDataCheck = false;
        this.getList();

        // this.$store.dispatch('dict/cleanDict');
      });
    },
    submitoneClickSync() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
        // second: this.second,
      };
      this.openLoading1();
      oneClickSync(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.openone = false;
        this.getList();

        // this.$store.dispatch('dict/cleanDict');
      });
    },
    /** 同步品类信息 Warning*/
    handleRefreshsynProTypeData() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      // const obj = {
      //   startTime: this.timeGap.startTime,
      //   endTime: this.timeGap.endTime,
      // };
      this.openLoading1();
      synProTypeData(this.timeGap).then(() => {
        // this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    /** 同步订单状态 Warning*/
    handleRefreshsynOrderStatusData() {
      // this.$modal.msgWarning("数据正在同步，请稍候");

      // const obj = {
      //   startTime: this.timeGap.startTime,
      //   endTime: this.timeGap.endTime,
      // };
      this.openLoading1();
      synOrderStatusData(this.timeGap).then(() => {
        // this.$modal.msgSuccess("同步数据成功");
        this.$modal.closeLoading();
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type == 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传导入文件大小不能超过 100MB!");
      }

      return isLt2M;
    },
    handleRemove(file, fileList) {
      if (!fileList.length) {
        this.hasFile = false;
      }
      this.dataForm.file = null;
    },
    handleChange(file, fileList) {
      if (fileList.length >= 2) {
        return;
      }
      if (fileList.length === 1) {
        this.hasFile = true;
      }
      this.dataForm.file = file;
    },
    //确定按钮
    //调用组件upload的submit方法，从而触发httpRequest方法，实现手动上传
    submitUpload() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.$refs.uploadImport.submit();
        }
      });
    },
    httpRequest(param) {
      if (this.dataForm.name.length < 3) {
        this.$modal.msgWarning("请选择到店铺");
        return;
      }
      let fd = new FormData();
      fd.append("file", param.file); // 传文件
      fd.append("salesGrade", this.dataForm.name);
      // fd.append("brand", this.dataForm.name[0]);
      // fd.append("channel", this.dataForm.name[1]);
      //dataPar.file.raw
      console.log(JSON.stringify(fd));
      this.openLoading();
      axios
        .post(
          process.env.VUE_APP_BASE_API + "/live/BiLiveOrder/importData",
          fd,
          {
            headers: {
              header: { responseType: "blob" },

              Authorization: "Bearer " + getToken(),
              "Content-Type": "multipart/form-data",
            }, //定义内容格式,很重要
            // // timeout: 20000,
          }
        )
        .then((response) => {
          this.$modal.closeLoading();
          console.log(response);
          if (response.data.code == 200) {
            this.dialogVisible = false;

            this.$modal.msgSuccess("导入成功");
            this.hasFile = false;
            this.getList();
          } else {
            this.$modal.msgError("导入失败");
          }
        });
    },
    changecascadeList(value) {
      console.log(JSON.stringify(value));
    },
    //部门文件导入修改打开
    daoru() {
      this.dialogVisible = true;
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在导入，请稍候！");
    },
    /** 查询品牌渠道店铺关系列表 */
    getdataSourceList() {
      listAll().then((response) => {
        let list = [];
        response.forEach((item) => {
          if (item.isTalentLive == "是") {
            list.push(item);
          }
        });
        let result = this.transformData(list);
        this.cascadeList = result;
        this.dataForm.name = [
          result[0].label,
          result[0].children[0].label,
          result[0].children[0].children[0].label,
        ];
      });
    },

    //店铺渠道品牌转换

    transformData(data) {
      let result = [];

      data.forEach((item) => {
        let brand = item.brand;
        let channel = item.channel;
        let shopName = item.channelShopName;

        // 如果brand在结果数组中不存在，则创建一个新的数组
        let brandIndex = result.findIndex(
          (brandObj) => brandObj.label === brand
        );
        if (brandIndex === -1) {
          result.push({
            label: brand,
            value: brand,
            children: [],
            disabled: true,
          });
          brandIndex = result.length - 1;
        }

        // 如果channel在当前brand的children数组中不存在，则创建一个新的数组
        let channelIndex = result[brandIndex].children.findIndex(
          (channelObj) => channelObj.label === channel
        );
        if (channelIndex === -1) {
          result[brandIndex].children.push({
            label: channel,
            value: channel,
            children: [],
            disabled: true,
          });
          channelIndex = result[brandIndex].children.length - 1;
        }

        // 如果shopName在当前channel的children数组中不存在，则创建一个新的数组
        let shopIndex = result[brandIndex].children[
          channelIndex
        ].children.findIndex((shopObj) => shopObj.label === shopName);
        if (shopIndex === -1) {
          result[brandIndex].children[channelIndex].children.push({
            label: shopName,
            value: shopName,
            // children: []
          });
        }
      });

      return result;
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询直播订单列表 */
    getList() {
      this.loading = true;
      listBiLiveOrder(this.queryParams).then((response) => {
        this.BiLiveOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        brand: null,
        channel: null,
        shopName: null,
        orderNumber: null,
        orderStatus: null,
        productCode: null,
        productQuantity: null,
        avgProPrice: null,
        productType: null,
        liveType: null,
        dataDate: null,
        payAmount: null,
        returnAmount: null,
        discountRate: null,
        talentId: null,
        talentName: null,
        estimateCommission: null,
        commissionRate: null,
        dataYear: null,
        dataMonth: null,
        dataWeek: null,
        createTime: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {};
      this.value2 = "";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.list = selection.map((item) => item);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加直播订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiLiveOrder(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改直播订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiLiveOrder(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiLiveOrder(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除直播订单编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiLiveOrder(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "live/BiLiveOrder/export",
        {
          ...this.queryParams,
        },
        `BiLiveOrder_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" >
// .el-scrollbar__wrap {
//   overflow: hidden;
//   margin-bottom: 0px !important;
//   margin-right: 0px !important;
// }
</style>